package com.talkyun.openx;

import org.springframework.beans.factory.FactoryBean;

import java.util.concurrent.ThreadPoolExecutor;

public class RestfulSpringFactory extends RestfulServiceFactory implements FactoryBean {
    private String mapping;
    private Class<?> clazz;

    public RestfulSpringFactory() {

    }

    public RestfulSpringFactory(String url, int threadNum) {
        super(url, threadNum);
    }

    public RestfulSpringFactory(String url, ThreadPoolExecutor executor) {
        super(url, executor);
    }

    public void setMapping(String mapping) {
        this.mapping = mapping;
    }

    public void setInterface(String clazz) throws ClassNotFoundException {
        this.clazz = Class.forName(clazz);
    }

    public Class<?> getInterface() {
        return clazz;
    }

    @Override
    public Object getObject() throws Exception {
        if (mapping == null) {
            return super.getService(clazz);
        } else {
            return super.getService(mapping, clazz);
        }
    }

    @Override
    public Class<?> getObjectType() {
        return clazz;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

}
